﻿using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using FileService.common;
using FileService.config;
using FileService.model;

namespace FileService.controller
{
    [Route("operate")]
    public class OperateController : Controller
    {
        private IWebHostEnvironment host;
        public OperateController(IWebHostEnvironment _host)
        {
            host = _host;
        }
        [Route("makefileszip")]
        public async Task<string> MakeFilesZip(string realfiles, string zipfiles)
        {
            ResultHelper resultHelper = new ResultHelper();
            string guid = Guid.NewGuid().ToString();
            List<string> realfilelist = new List<string>();
            realfilelist.AddRange(realfiles.Split(','));
            List<string> zipfilelist = new List<string>();
            zipfilelist.AddRange(zipfiles.Split(','));
            SharpZipLibUtil sharp = new SharpZipLibUtil();
            ZipBaseInfo zipBaseInfo = new ZipBaseInfo();
            zipBaseInfo.Name = guid.Replace("-", "") + ".zip";
            zipBaseInfo.Password = "123456";
            zipBaseInfo.RealFilePaths = realfilelist;
            zipBaseInfo.ZipFilePaths = zipfilelist;
            await sharp.MakeFilesZipAsync(zipBaseInfo);
            resultHelper.Code = 0;
            resultHelper.Msg = "压缩成功";
            resultHelper.Data = new { name = zipBaseInfo.Name };
            return resultHelper.GetResultInfo();
        }
    }
}